#lang scheme/base


(require scheme/list)
(require scheme/function)


;Geriatric Depression Rating Scale, A Screening Test for Depression
;http://counsellingresource.com/lib/quizzes/depression-testing/geriatric-depression/
;http://www.wai.wisc.edu/pdf/phystoolkit/screeningtools/gds-15.pdf



(provide quiz?)
;own-history format (#t/#f question-number score)
(define (quiz? history own-history)
  (cond ((and (not (null? own-history)) (equal? (car own-history) 'done)) #f) 
        ((and (not (null? own-history)) (car own-history)) #t)
        (else (< (random 101) 50)))) ;!!!!!!!!! for testing puproses only

(provide quiz-reply)
(define (quiz-reply history own-history) 
  
  (cond ((null? own-history) (append (list (car (list-ref (questions) 0)) (list #t 0 0)) history))
        ((car own-history) 
         (cond ((< (second own-history) (- (length (questions)) 1)) 
                (append (list '(ok, lets go further) 
                              (list #f (second own-history) (+ (third own-history) (get-score (second own-history) (car history))))) 
                        (cdr history)))
               (else (append (list (scale-answers (+ (third own-history) (get-score (second own-history) (car history)))) '(done)) history)))
         )
        (else (append (list (car (list-ref (questions) (+ 1 (second own-history)))) (list #t (+ 1 (second own-history)) (third own-history))) history))))



(define (questions)
  '(((Are you basically satisfied with your life ?) (No no))
    ((Have you dropped many of your activities and interests ?) (Yes yes))
    ((Do you feel that your life is empty ?) (Yes yes))
    ((Do you often get bored ?) (Yes yes))
    ((Are you in good spirits most of the time ?) (No no))
    ((Are you afraid that something bad is going to happen to you ?) (Yes yes))
    ((Do you feel happy most of the time ?) (No no))
    ((Do you often feel helpless ?) (Yes yes))
    ((Do you prefer to stay at home, rather than going out and doing new things ?) (Yes yes))
    ((Do you feel you have more problems with memory than most ?) (Yes yes))
    ((Do you think it is wonderful to be alive now ?) (No no))
    ((Do you feel pretty worthless the way you are now ?) (Yes yes))
    ((Do you feel full of energy ?) (No no))
    ((Do you feel that your situation is hopeless ?) (Yes yes))
    ((Do you think that most people are better off than you are?) (Yes yes))))

;0 to 4, Normal Range
;5 to 8, Mild Depression
;9 to 11, Moderate Depression
;12 to 15, Severe Depression

(define (get-score question-number answer) 
  (if (member (car answer) (second (list-ref (questions) question-number))) 1 0))

(define (scale-answers score) 
  
  (cond ((< score 5) '(You do not appear to be experiencing any depressive symptoms at this time. 
                              If this changes, you may need to seek further diagnosis and treatment.))
        ((< score 9) '(You appear to be experiencing some very mild depressive symptoms, 
                            most of which are commonly found amongst the general population. 
                            It is unclear whether or not you suffer these problems severely 
                            enough to need to seek further diagnosis and treatment.))
        ((< score 12) '(You appear to be experiencing some moderate depressive symptoms, 
                                 many of which are commonly found amongst the general population, but border on the possibility 
                                 of a depressive episode. It is unclear whether or not you suffer these problems severely enough to 
                                 need to seek further diagnosis and treatment.))
        (else '(You appear to be suffering from severe depressive symptoms commonly associated 
                       with serious depressive disorders. You would likely benefit from the 
                       immediate attention of your physician or a trained mental health professional 
                       for further evaluation and a more accurate diagnosis and treatment.))))
